import { createStore } from 'vuex';
import StorageManager from '@/utils/StorageManger';
import { UserInfo } from '@/types';
export default createStore({
    state: {
        userinfo: StorageManager.get<UserInfo>('userinfo') || {
            userId: '',
            username: '',
            identify: '',
            createTime: '',
            avatar: '',
            token: '',
        },
        // adminInfo: StorageManager.get<UserInfo>('adminInfo') || {}
    },
    getters: {
        isLogin: state => {
            return state.userinfo.userId !== '';
        },
    },
    mutations: {
        login: (state, payload) => {
            state.userinfo = payload;
            StorageManager.set('userinfo', state.userinfo);
        },
        logout: state => {
            state.userinfo = {
                userId: '',
                username: '',
                identify: '',
                createTime: '',
                token: '',
                avatar: '',
            };
            StorageManager.remove('userinfo');
        },
        setUserInfo: (state, payload) => {
            state.userinfo.username = payload.username;
            state.userinfo.avatar = payload.avatar;
            StorageManager.set('userinfo', state.userinfo);
        },
    },
    actions: {},
    modules: {},
});
